﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace AutoInsurance
{
    public partial class autoData : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string id_client = Request.QueryString["idclient"];
                string strSqlConnection = "Data Source=localhost\\sqlexpress;Initial Catalog=Autoinsurance;Integrated Security=True";

                SqlConnection sqlCon = new SqlConnection(strSqlConnection);


                sqlCon.Open();


                string strQuery = "SELECT * FROM Auto where id_client=" + id_client;
                DataSet ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = new SqlCommand(strQuery, sqlCon);
                da.Fill(ds, "Auto");
                GridView1.DataSource = ds.Tables["Auto"];
                this.DataBind();

                sqlCon.Close();
            }
            catch (Exception ex) {
                Server.Transfer("Error.aspx?error=" + ex.Message);
            }
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                String vin_code = GridView1.SelectedRow.Cells[1].Text;
                string myUrl = "policyData.aspx?vincode=" + vin_code;
                Response.Redirect(myUrl);
            }
            catch (Exception ex)
            {
                Server.Transfer("Error.aspx?error=" + ex.Message);
            }
        }
        }

            
    }
